
package com.wyzz.hr.bo.impl;

import com.wyzz.hr.base.FileOperate;
import com.wyzz.hr.bo.IEmpEduHisBo;
import com.wyzz.hr.dao.IEmpEduHisDao;
import com.wyzz.hr.pojo.Emphistoryedu;
import com.wyzz.hr.pojo.Employee;

import java.util.List;
import org.hibernate.FetchMode;
import org.hibernate.criterion.*;


public class EmpEduHisBoImpl implements IEmpEduHisBo {

	public EmpEduHisBoImpl() {
	}

	public String insert(Emphistoryedu emphis) {
		empEduHisDao.saveObject(emphis);
		return emphis.getEheId();
	}

	public List search(String employeeId) {
		DetachedCriteria detachedCriteria = DetachedCriteria
				.forClass(com.wyzz.hr.pojo.Emphistoryedu.class);
		detachedCriteria.setFetchMode(Emphistoryedu.PROP_EMPLOYEE,
				FetchMode.DEFAULT);
		detachedCriteria.add(Restrictions.eq((new StringBuilder()).append(
				Emphistoryedu.PROP_EMPLOYEE).append(".").append(
				Employee.PROP_ID).toString(), employeeId));
		detachedCriteria
				.addOrder(Order.desc(Emphistoryedu.PROP_EHE_DATE_START));
		List result = empEduHisDao.findByCriteria(detachedCriteria);
		return result;
	}

	public boolean deleteAttach(String contractId, String fileName) {
		try {
			FileOperate.deleteFile("sys.profile.file.path", fileName);
			String hql = (new StringBuilder())
					.append(
							"update Emphistoryedu set eheAttachment=null where eheId='")
					.append(contractId).append("'").toString();
			empEduHisDao.exeHql(hql);
			return true;
		} catch (Exception e) {
			return false;
		}
	}

	public void delete(String eheId) {
		String hql = (new StringBuilder()).append(
				"delete from Emphistoryedu where eheId='").append(eheId)
				.append("'").toString();
		empEduHisDao.exeHql(hql);
	}

	public void update(Emphistoryedu emphis) {
		empEduHisDao.saveOrupdate(emphis);
	}

	public List search(Emphistoryedu empHis) {
		DetachedCriteria detachedCriteria = DetachedCriteria
				.forClass(com.wyzz.hr.pojo.Emphistoryedu.class);
		detachedCriteria.setFetchMode(Emphistoryedu.PROP_EMPLOYEE,
				FetchMode.DEFAULT);
		detachedCriteria.add(Restrictions.eq(Emphistoryedu.PROP_EHE_ID, empHis
				.getEheId()));
		detachedCriteria
				.addOrder(Order.desc(Emphistoryedu.PROP_EHE_DATE_START));
		List emphisObj = empEduHisDao.findByCriteria(detachedCriteria);
		return emphisObj;
	}

	public Emphistoryedu load(String eheId, String fetches[]) {
		return (Emphistoryedu) empEduHisDao.loadObject(
				com.wyzz.hr.pojo.Emphistoryedu.class, eheId, fetches,
				new boolean[0]);
	}

	public IEmpEduHisDao getEmpEduHisDao() {
		return empEduHisDao;
	}

	public void setEmpEduHisDao(IEmpEduHisDao empEduHisDao) {
		this.empEduHisDao = empEduHisDao;
	}

	private IEmpEduHisDao empEduHisDao;
}
